package com.fifth.home.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.Zone;
import com.fifth.home.service.IZoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 专区 前端控制器
 * </p>
 *
 * @author 第五组
 * @since 2022-09-01
 */
@RestController
@RequestMapping("/home/zone")
@Api(tags = "专区相关接口")
public class ZoneController {
    @Autowired
    private IZoneService zoneService;

    /**
     * 前端显示排序
     * @return
     */
    @ApiOperation("查询专区接口(前端调用)")
    @GetMapping("prefecture")
    public CommonResult prefecture(){
        return zoneService.prefectureSearch();
    }

    /**
     * 专区  模糊查询
     * @param zone
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ApiOperation("查询专区接口(后台调用)")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "zone",value = "Zone实体类",dataType = "Zone"),
                    @ApiImplicitParam(name = "currentPage",value = "当前页码",dataType = "int"),
                    @ApiImplicitParam(name = "pageSize",value = "每页条数",dataType = "int")
            }
    )
    @PostMapping("fuzzySearch/{currentPage}/{pageSize}")
    public CommonResult fuzzySearch(@RequestBody Zone zone, @PathVariable Integer currentPage, @PathVariable Integer pageSize){
        return zoneService.fuzzyQuery(zone,currentPage,pageSize);
    }

    /**
     * 新增专区
     * @param zone
     * @return
     */
    @ApiOperation("添加专区接口(后台调用)")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "zone",value = "Zone实体类",dataType = "Zone")
            }
    )
    @PostMapping("insertPrefecture")
    public CommonResult insertPrefecture(@RequestBody Zone zone){
        return zoneService.addPrefecture(zone);
    }

    /**
     * 修改专区信息
     * @param zone
     * @return
     */
    @ApiOperation("修改专区信息接口(后台调用)")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "zone",value = "Zone实体类",dataType = "Zone")
            }
    )
    @PostMapping("updatePrefecture")
    public CommonResult updatePrefecture(@RequestBody Zone zone){
        return zoneService.updatePrefectureDetails(zone);
    }


    /**
     * 删除专区   物理删除
     * @param id
     * @return
     */
    @ApiOperation("删除专区接口(后台调用)")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id",value = "专区id",dataType = "String")
            }
    )
    @GetMapping("removePrefecture/{id}")
    public CommonResult removeNavigation(@PathVariable String id){
        return zoneService.deletePrefecture(id);
    }


    /**
     * 修改导航 专区状态  0正常  1禁用
     * @param
     * @return
     */
    @ApiOperation("修改专区状态(后台调用)")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id",value = "专区id",dataType = "String"),
                    @ApiImplicitParam(name = "isDisable",value = "状态 0启动 1禁用",dataType = "String")
            }
    )
    @PostMapping("updateDisable/{id}/{isDisable}")
    public CommonResult updateDisable(@PathVariable String id,@PathVariable String isDisable){
        return zoneService.updateStatus(id,isDisable);
    }



}
